package com.vf.admin.client.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppRoomCollect;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * 房间背景
 */
@Repository
public class AppRoomCollectDao extends BaseDao<AppRoomCollect> {

    /**
     * 查询列表
     */
    public AppRoomCollect OfficialPersonalList(Integer userid,Integer roomid) {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_room_collect where 1=1  ");
        sbStr.append(" and userid = ? ");
        paramList.add(userid);
        sbStr.append(" and roomid = ? ");
        paramList.add(roomid);
        String sql = sbStr.toString();
        return this.queryObj(sql,paramList, AppRoomCollect.class);
    }


    /**
     * 查询列表
     */
    public List<AppRoomCollect> findList(Integer userid, SplitPageBean splitPageBean) {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_room_collect where 1=1  ");
        sbStr.append(" and userid = ? ");
        paramList.add(userid);

        String sql = sbStr.toString();
        return this.queryList(sql,paramList, AppRoomCollect.class,splitPageBean);
    }


    /**
     * 详情
     */
    public AppRoomCollect get(Integer id) {
        if (StringEx.isNullOrLing(id)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_room_collect where 1=1");
        sbStr.append(" and id = ? ");
        paramList.add(id);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppRoomCollect.class);
    }

    /**
     * 详情
     */
    public AppRoomCollect getRoomcode(Integer roomcode) {
        if (StringEx.isNullOrLing(roomcode)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_room_collect where 1=1");
        sbStr.append(" and roomcode = ? ");
        sbStr.append(" limit 1 ");
        paramList.add(roomcode);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppRoomCollect.class);
    }


    /**
     * 更新房间信息
     */
    public void uodateData(Integer roomcode,Integer xingzhi,Integer roomtypeid,String roomtypename,String roomname,String roomimg) {
        if(StringEx.isNull(roomcode)){
            return ;
        }
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuffer sql =new StringBuffer(" update app_room_collect set xingzhi=? ") ;
        paramList.add(xingzhi);
        sql.append(" ,roomtypeid=? ");
        paramList.add(roomtypeid);
        sql.append(" ,roomtypename=? ");
        paramList.add(roomtypename);
        sql.append(" ,roomname=? ");
        paramList.add(roomname);
        sql.append(" ,roomimg=? ");
        paramList.add(roomimg);
        sql.append(" where roomcode=? ");
        paramList.add(roomcode);
        this.update(sql.toString(),paramList);
    }

    /**
     * 添加/修改
     */
    public void save(AppRoomCollect haoYou) {
        if (haoYou.getId() != null && haoYou.getId() > 0) {
            this.update(haoYou);
        } else {
            haoYou.setId(this.add(haoYou));
        }
    }

    /**
     * 删除
     */
    public void del(Integer id) {
        if (id <= 0) {
            return;
        }
        String sql = "delete  from app_room_collect where id = ?";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(id);
        this.del(sql, paramList);
    }
}
